package com.jlf.controller.engine.entity.criterion;

import com.jlf.core.engine.domain.SchemaCriterionDO;
import com.jlf.core.engine.domain.SchemaDomainDO;
import com.jlf.core.engine.domain.SchemaFieldDO;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 检索条件的详情输出
 *
 * @author wujr
 * 2023/7/28
 * @version 1.0
 * 【变更历史】
 * [wujr 2023/7/28 1.0 新增]
 */
@Getter
@Setter
public class SchemaCriterionDetailOutput {
    private Long id;
    /**
     * 所属的模型 {@link SchemaDomainDO#getDomainCode()}
     */
    private String domainCode;
    /**
     * 查询条件的编码
     */
    private String criterionCode;
    /**
     * 该查询字段对应的模型字段 {@link SchemaFieldDO#getClassFieldCode()}
     * 如果该查询条件需要支持多个字段，则多个字段用逗号分隔，字段之间用or关联
     */
    private List<String> classFieldCode;
    private List<Field> domainField;
    /**
     * 对应的数据类型 {@link SchemaFieldDO#getClassDataType()}
     */
    private Integer classDataType;
    private Integer status;
    private Integer priority;
    /**
     * 是否支持eq查询，默认：true
     */
    private Boolean supportEqual = true;
    /**
     * 是否支持ne查询，默认：false
     */
    private Boolean supportNotEqual = false;
    /**
     * 是否支持大于等于，默认：false
     */
    private Boolean supportGreatEqual = false;
    /**
     * 是否支持大于，默认：false
     */
    private Boolean supportGreatThan = false;
    private Boolean supportLessThan = false;
    private Boolean supportLessEqual = false;
    /**
     * 是否支持like查询，仅针对varchar的字段有效，默认：false，对于varchar字段，默认：true
     */
    private Boolean supportLike = false;
    /**
     * 是否支持notLike查询，仅针对varchar的字段有效，默认：false
     */
    private Boolean supportNotLike = false;
    private Boolean supportLikeLeft = false;
    private Boolean supportLikeRight = false;
    private Boolean supportNotLikeLeft = false;
    private Boolean supportNotLikeRight = false;

    @Getter
    @Setter
    public static class Field{
        private String classFieldCode;
        private String displayName;
        private String jdbcFieldCode;

        public Field(SchemaFieldDO field){
            this.classFieldCode = field.getClassFieldCode();
            this.displayName = field.getDisplayName();
            this.jdbcFieldCode = field.getJdbcFieldCode();
        }
    }

    public SchemaCriterionDetailOutput(SchemaCriterionDO record){
        this.id = record.getId();
        this.domainCode = record.getDomainCode();
        this.criterionCode = record.getCriterionCode();
        this.classDataType = record.getClassDataType();
        this.classFieldCode = Arrays.asList(StringUtils.split(record.getClassFieldCode(), ','));
        this.status = record.getStatus();
        this.priority = record.getPriority();
        this.supportEqual = record.isEqCriterion();
        this.supportNotEqual = record.isNeCriterion();
        this.supportGreatEqual = record.isGeCriterion();
        this.supportGreatThan = record.isGtCriterion();
        this.supportLessEqual = record.isLeCriterion();
        this.supportLessThan = record.isLtCriterion();
        this.supportLike = record.isLikeCriterion();
        this.supportNotLike = record.isNotLikeCriterion();
        this.supportLikeLeft = record.isLikeLeftCriterion();
        this.supportLikeRight = record.isLikeRightCriterion();
        this.supportNotLikeLeft = record.isNotLikeLeftCriterion();
        this.supportNotLikeRight = record.isNotLikeRightCriterion();
    }
}
